from openpyxl import load_workbook
from openpyxl import Workbook
'''
读取xlsx文件返回2维列表
filename:xlsx文件名

'''
def read_xlsx(filename):
    wb=load_workbook(filename)
    ws=wb.active
    row_num=ws.max_row
    column_num=ws.max_column

    total_list=[]
    for r in range(1,row_num+1):
        row_list=[]
        for c in range(1,column_num+1):
            value=ws.cell(r,c).value
            row_list.append(value)

        total_list.append(row_list)
    return total_list

'''
写入xlsx文件
filename:文件名
data_list:二维列表
按行写入
'''
def write_xlsx(filename,data_list):
    wb=Workbook()
    ws=wb.create_sheet()
    # ws.merge_cells('A1:K1')
    for row in data_list:
        print(row)
        ws.append(row)
    print('数据写入完成！！！')
    # ws.merge_cells('A1:K1')
    wb.save(filename)

file_value=read_xlsx('现场返修表2019-8-1.xlsx')
print(file_value)
write_xlsx('测试.xlsx',file_value)
